#include"mk.h"
#include"hgmcu.h"
uchar code smgsz[]={
0xC0,0xF9,0xA4,0xB0,
0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,
0xC6,0xA1,0x86,0x8E,0xff};
void delay(uint z)
{
	uint x,y;
	for(x=z;x>0;x--)
		for(y=110;y>0;y--);
}
void display(uchar qian,uchar bai,uchar shi,uchar ge,uchar cyc,uchar time)
{
uchar xh;
for(xh=0;xh<cyc;xh++)
		{
			//qbsg
			P0=qian;
			P20=0;
			delay(time);
			P20=1;
			P0=bai;
			P21=0;
			delay(time);
			P21=1;
			P0=shi;
			P22=0;
			delay(time);
			P22=1;
			P0=ge;
			P23=0;
			delay(time);
			P23=1;
		}
}
/*****************************************
							????
????????? display??
num=?? wz=????? t??????(??)
if(num/1000==0)	??????????
switch(b)				??????????
ge=table[ge];		???????16??
switch(wz)			?????
shownum(qian		????.??
****************************************/
void xs(uint num,uchar wz,uint t)
{
	uchar qian,bai,shi,ge,b;
	b=4;
	if(num/1000==0)
	{
		b--;
		if(num%1000/100==0)
		{
			b--;
			if(num%100/10==0)
			{b--;}
		}
	}
	switch(b)
	{
		case 1:
			{
				ge=num%10;
				shi=0x10;
				bai=0x10;
				qian=0x10;
				break;
			}
		case 2:
			{
				ge=num%10;
				shi=num%100/10;
				bai=0x10;
				qian=0x10;
				break;
			}
		case 3:
			{
				ge=num%10;
				shi=num%100/10;
				bai=num%1000/100;
				qian=0x10;
				break;
			}
		case 4:
			{
				ge=num%10;
				shi=num%100/10;
				bai=num%1000/100;
				qian=num/1000;
				break;
			}
		default:
			{
				break;
			}
	}
	ge=smgsz[ge];
	shi=smgsz[shi];
	bai=smgsz[bai];
	qian=smgsz[qian];
	switch(wz)
	{
		case 1:
		{
			ge-=0x80;
			break;
		}
		case 2:
		{
			shi-=0x80;
			break;
		}
		case 3:
		{
			bai-=0x80;
			break;
		}
		case 4:
		{
			qian-=0x80;
			break;
		}
		default:
		{
			break;
		}
	}
		display(qian,bai,shi,ge,t,1);
}
void xszfc(uchar tzfc[4],uint sz_t)
{
	uchar code smgascii[]={
	0xFF,0x79,0xDD,0x81,0x9A,0x9C,0x84,0xFD,//0x20-0x27 32-39
	0xC6,0xF0,0xBC,0xB9,0xFB,0xBF,0x7F,0xAD,//0x28-0x2F 40-47
	0x89,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,//0x30-0x37 48-55
	0x80,0x90,0x7D,0x77,0x9E,0xBE,0xBC,0x38,//0x38-0x3F 56-63
	0x22,0x88,0x83,0xA7,0xA1,0x86,0x8E,0xC2,//0x40-0x47 64-71
	0x8B,0xF0,0xF1,0x8A,0xC7,0xAA,0xAB,0xA3,//0x48-0x4F 72-79
	0x8C,0x98,0xAF,0xD2,0xCE,0xC1,0xE3,0xE2,//0x50-0x57 80-87
	0x89,0x8D,0xE4,0xC6,0x9B,0xF0,0xDC,0xF7};//0x58-0x5F
	uchar sa_for,ascii,sat_out,smgzmt,qian,bai,shi,ge;
	for(sa_for=0;sa_for<4;sa_for++)
	{
		ascii=tzfc[sa_for];
		if(ascii>0x60)
			{sat_out=ascii-0x40;}
		else
			{sat_out=ascii-0x20;}
		smgzmt=smgascii[sat_out];
		if(ascii==0x7c)
			{smgzmt=0xf9;}
		switch(sa_for)
		{
			case 0:
			{qian=smgzmt;break;}
			case 1:
			{bai=smgzmt;break;}
			case 2:
			{shi=smgzmt;break;}
			case 3:
			{ge=smgzmt;break;}
		}
	}
	display(qian,bai,shi,ge,sz_t,1);
}
void srnum(uint *srn_num)
{
	uchar jr;
	xszfc(" shu",200);
	xszfc("  ru",200);
	xszfc(" shu",200);
	xszfc("  zi",200);
	while(1)
	{
		if(k2==0)
		{
			if(k4==0)
				{srn_num+=10;}
			else
				{srn_num++;}
			while(!k2)
			{
			if(k3==0)
				{
					if(jr==0)
					{
						if(k4==0)
						{srn_num+=990;}
					 else
						{srn_num+=99;}
						jr=1;
					}
					else
					{
						if(k4==0)
							{srn_num+=1000;}
						else
							{srn_num+=100;}
					}
						while(!k3)
						{xs(srn_num,0,10);}
				}
				else
				{xs(srn_num,0,10);}
			}
			jr=0;
		}
		if(k3==0)
		{
			if(k4==0)
				{srn_num-=10;}
			else
				{srn_num--;}
				while(!k3)
				{
					if(k2==0)
					{
						if(jr==0)
						{
							if(k4==0)
							{srn_num-=990;}
						 else
							{srn_num-=99;}
							jr=1;
						}
						else
						{
							if(k4==0)
								{srn_num-=1000;}
							else
								{srn_num-=100;}
						}
							while(!k2)
							{xs(srn_num,0,10);}
					}
					else
					{xs(srn_num,0,10);}
				}
			jr=0;
		}
		if(k1==0)
		{
			uchar sftc;
			while(!k1);
			{
				xszfc("  ok",10);
				if(k2==0)
				{sftc=1;}
			}
			if(sftc==0)
			{break;}
		}
		xs(srn_num,0,10);
	}
}